package com.mybatis_stu.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.mybatis_stu.mapper.ClazzMapper;
import com.mybatis_stu.pojo.*;
import com.mybatis_stu.service.ClazzService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

@Service
public class ClazzServiceImpl  implements ClazzService {

    @Autowired
    private ClazzMapper clazzMapper;

    @Override
    public void add(Clazz clazz) {
        clazzMapper.insert(clazz);
    }

    @Override
    public void deleteByIds(List<Integer> ids) {
        clazzMapper.deleteByIds(ids);
    }

    @Override
    public List<Clazz> list() {
        return clazzMapper.list();
    }

    /**
     *根据职位Id查询班主任列表
     * */
    @Override
    public List<ClassResponse> getTeachersByPositionId(Integer positionId) {
        return clazzMapper.getTeachersByPositionId(positionId);

    }

    /**
     *带条件的分页查询
     * */
    @Override
    public PageBean page(Integer page, Integer pageSize, String name, LocalDate begin, LocalDate end) {
        //设置分页参数
        PageHelper.startPage(page, pageSize);
        //执行条件分页查询
        List<Clazz> empList = clazzMapper.list(name, begin, end);
        //获取查询结果
        Page<Clazz> p = (Page<Clazz>) empList;
        //封装PageBean
        PageBean pageBean = new PageBean(p.getTotal(), p.getResult());
        return pageBean;
    }



    /**
     *修改班级
     * */
    @Override
    public void updateInfo(Clazz clazz) {
        clazz.setUpdateTime(LocalDateTime.now());
        clazzMapper.updateInfo(clazz);
    }


}
